package testing;

import java.util.Vector;

import clang.control.CodeBlock;
import clang.control.ExecutionThread;
import clang.control.ReturnStatement;
import clang.control.VariableDefinition;
import clang.data.Expression;
import clang.data.VarName;
import clang.data.VarType;
import clang.data.Variable;
import clang.functions.Function;
import clang.functions.FunctionCall;

public class StdIo {

	public static void main(String[] args) {
		CodeBlock cb = new CodeBlock(ExecutionThread.get().getCurrentBlock());
		
		cb.append(new VariableDefinition("a", VarType.INT, 5.0));
		
		Variable hello = Variable.generateArray(cb, "Hello world! a = %d\n", "myArray");
		
		Vector<Expression> pfargs = new Vector<Expression>();
		pfargs.add(hello);
		pfargs.add(new VarName("a"));
		FunctionCall fcprintf = new FunctionCall("printf", pfargs);
		cb.append(fcprintf);
		
		cb.append(new ReturnStatement(0));
		
		Function mainFunc = new Function("main");
		mainFunc.setReturnType(VarType.INT);
		mainFunc.setBlock(cb);
		ExecutionThread.get().addFunction(mainFunc);
		
		ExecutionThread.get().runProgram();
		
	}

}
